package com.wty.basic.objectReference;


import com.wty.basic.pojo.School;
import com.wty.basic.pojo.Student;

/**
 * equals的实验
 *
 */
public class Test1 {
    public static void main(String args[]){
        int a=1;
        int b=1;
        System.out.println(a==1);//true


        /**
         * 字符串类型重写了eqauls
         */
        String s1=new String("aaa");
        String s2=new String("aaa");
        System.out.println(s1==s2); //false
        System.out.println(s1.equals(s2)); //true

        /**
         * 自定义类型需要重写equals
         */
        Student stu1=new Student();
        Student stu2=new Student();
        System.out.println(stu1==stu2);//false
        System.out.println(stu1.equals(stu2));//重写equals之后为true 否则为false

        /**
         * 自定义类型如果属性是对象，对象所属的类也要重写equals，equals才能比较值
         */
        Student stu3=new Student("wty",18,new School("tust",2000));
        Student stu4=new Student("wty",18,new School("tust",2000));
        System.out.println(stu3==stu4);//false
        System.out.println(stu3.equals(stu4));//重写equals之后为true 否则为false
    }
}
